#define  _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
void swap(int* arr, int x, int y)
{
    int temp = arr[x];
    arr[x] = arr[y];
    arr[y] = temp;
}
int main()
{
    int n = 0, m = 0, x = 0, y = 0, a = 0, b = 0;
    scanf("%d %d", &n, &m);
    int arr[1000] = { 0 };
    int i = 0;
    for (i = 0; i < n; i++)
        scanf("%d", &arr[i]);
    int temp = m;
    while (temp)
    {
        scanf("%d %d", &x, &y);
        for (i = 0; i < n; i++)
        {
            if (arr[i] == x)
                a = i;
            else if (arr[i] == y)
                b = i;
        }
        if(a != b)
            swap(arr, a, b);
        temp--;
    }
    for (i = 0; i < n; i++)
        printf("%d\n", arr[i]);
    return 0;
}